package pool;

import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Map;

/**
 * 用户配置模式、删除、添加、修改
 */
public enum ConfigMode {
  DELETE, ADD, MODIFY, OTHER;
  
  static final Map<String, ConfigMode> ENUM_MAP = Maps.newHashMap();
  static {
    Arrays.asList(ConfigMode.values()).forEach(value -> ENUM_MAP.put(value.name(), value));
  }
  
  public static ConfigMode fromString(String mode) {
    if (StringUtils.isEmpty(mode)) {
      return OTHER;
    }
    ConfigMode rule = ENUM_MAP.get(mode.trim().toUpperCase());
    return rule == null ? OTHER : rule;
  }
}
